﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;


namespace TrayTool
{
  static class WindowsAPI
  {
    public const int WM_SHOWWINDOW = 0x0018;
    public const int WM_HOTKEY = 0x0312;

    [DllImport("user32.dll")]
    public static extern IntPtr GetDesktopWindow();

    [DllImport("user32.dll")]
    public static extern IntPtr WindowFromPoint(Point point);

    [DllImport("user32.dll")]
    public static extern IntPtr GetParent(IntPtr hWnd);

    [DllImport("user32.dll")]
    public static extern IntPtr GetAncestor(IntPtr hWnd, uint gaFlags);
    public const uint GA_PARENT = 1;
    public const uint GA_ROOT = 2;
    public const uint GA_ROOTOWNER = 3;

    [DllImport("user32.dll")]
    public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

    [DllImport("user32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll")]
    public static extern long SendMessage(IntPtr hWnd, uint Msg, uint wParam, long lParam);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool ShowWindow(IntPtr handle, ShowWindowCmd nCmdShow);
    public enum ShowWindowCmd
    {
      Hide = 0,
      Normal,
      ShowMinimized,
      Maximize,
      ShowNoActivate,
      Show,
      Minimize,
      ShowMinNoActive,
      ShowNA,
      Restore,
      Default,
      ForceMinimize
    }
    public const uint SW_HIDE = 0;
    public const uint SW_SHOW = 5;

    [DllImport("user32.dll")]
    public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, Keys vk);
    public const uint MOD_ALT = 1;
    public const uint MOD_CTRL = 2;
    public const uint MOD_SHIFT = 4;
    public const uint MOD_WIN = 8;

    [DllImport("user32.dll")]
    public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
  }
}
